package com.example.shopping.member.controller;

import com.example.shopping.JsonResult;
import com.example.shopping.member.entity.member;
import com.example.shopping.member.mapper.MemberMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
public class MemberController {

    @Autowired
    MemberMapper memberMapper;
    //查询
    @RequestMapping("/api/member/list")
    public  JsonResult getmemberlist(){
        List<member> member= memberMapper.getmemberlist();
        return  new JsonResult(true,"查询成功",member);
    }

    //修改会员金额
    @RequestMapping("/api/member/updmemberPrice")
    public JsonResult updmemberPrice(int cardprice,int id){
        int member=memberMapper.updmemberPrice(cardprice, id);
        if (member!=0){
            return new JsonResult(true,"充值金额成功",member);
        }else{
            return new JsonResult(false,"充值金额失败",member);
        }
    }


    //按照id查询会员
    @RequestMapping("/api/member/listId")
    public  JsonResult getmember_ID_list(int userid){
        List<member> member= memberMapper.getmember_ID_list(userid);
        if (member!=null){
            return  new JsonResult(true,"查询成功",member);
        }else{
            return  new JsonResult(false,"查询没有该会员",null);
        }
    }
    //删除
    @RequestMapping("/api/dele/member")
    public  JsonResult delememberlist(int id){
       int member= memberMapper.delememberlist(id);
        return  new JsonResult(true,"删除成功",member);

    }
    //id查询
    @RequestMapping("/api/addmember/id")
    public JsonResult getmemberid(int id){
        List<member> memberid= memberMapper.getmemberid(id);
        return  new JsonResult(true,"查询成功",memberid);
    }
    //修改
    @RequestMapping("/api/updmember/xiugai")
    public JsonResult updmember(int state , String vaildtime ,int id){
        int memberxg= memberMapper.updmember(state,vaildtime,id);
        return  new JsonResult(true,"修改成功",memberxg);
    }
    //增加
    @RequestMapping("/api/addmember/add")
    public JsonResult updmember(int userid, int carddengji, int cardprice, String cardname, int state,String vaildtime){

        int addmember= memberMapper.addmember( userid,carddengji,cardprice,cardname,state,vaildtime);
        return  new JsonResult(true,"增加成功",addmember);
    }


}   
